
<?php
	
	include("bd/conexao/config.php");
	session_start(); 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>	<?php echo $pagetitle; ?> </title>		

		<!-- CSS -->	
		<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
		<link href="css/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
		<!--<link href="css/docs.min.css" rel="stylesheet" type="text/css">	-->
		<link href="css/style.css" rel="stylesheet" type="text/css">		
		<link href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,400,700,300&amp;subset=latin,cyrillic-ext,vietnamese,cyrillic" rel="stylesheet" type="text/css">

	    <!-- SCRIPTS -->    
		<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
		<script src="https://code.jquery.com/jquery.js"></script> 	
		<script src="js/jquery.validate.js"></script> 		

		<!-- Include all compiled plugins (below), or include individual files as needed -->
	    <script src="js/bootstrap.min.js"></script>	
	 
	    <script> 	  		
	    	$(document).ready(function() {   

	    		/* Habilita menu Usuario caso perfil do usuário seja Administrador */

	    		if ("<?php echo $_SESSION['perfil_usuario']; ?>" == 'Administrador') {
					$('#menuUsuario').css('display', 'inline-block');
				} 

				/* Opção para acesso ao sistema 
				
				if ("<?php echo $_SESSION['altera_senha_prox_logon']; ?>" == '1') {	        	    
			      
			        $(window.document.location).attr('href','altera-senha.php');
		        
		        } else if  ("<?php echo $_SESSION['altera_senha_prox_logon']; ?>" == '0')  {
		        
		        	$(window.document.location).attr('href','default.php');			        

	        	} */		   		
				
	    		/* Evento Botões Cadastro */
	    	
				$('#btnNovaMusica').click(function() {
					$(window.document.location).attr('href','cad-musica.php');
				});

				$('#btnNovoUsuario').click(function() {
					$(window.document.location).attr('href','cad-usuario.php');
				});

				/* Evento Botões Modal */

				$('#modalAlertaEditaMusica #btnOkEditaMusica').click(function() { 
					$(window.document.location).attr('href','musica.php');
				});

				$('#modalAlertaCadastroMusica #btnOkCadastroMusica').click(function() { 
					$(window.document.location).attr('href','musica.php');
				});

				$('#modalAlertaEditaUsuario #btnOkEditaUsuario').click(function() { 
					$(window.document.location).attr('href','usuario.php');
				});

				$('#modalAlertaCadastroUsuario #btnOkCadastroUsuario').click(function() { 
					$(window.document.location).attr('href','usuario.php');
				});	 
				
				/* Evento Click - Link Sair do Sistema */
	    			
	    		$('#lnkSair').click(function() {    			

	    			$('#modalClose #textoAlertaClose').html("Deseja sair do sistema?");
	    			$('#modalClose').modal('show');
	    		});

	    		/* Evento checkbox Resetar Senha */

	    		$('#chkResetarSenha').change(function() {
	    			if ($(this).is(':checked')) {
						$('#divSenha').css('display', '');
						$('#divConfirmaSenha').css('display', '');
						$('#divResetarSenha').css('display', 'none');
	    			} else {
	    				$('#divSenha').css('display', 'none');
	    				$('#divConfirmaSenha').css('display', 'none');
	    			}
	    		});	    	

	    		/* Limpar Sessão e Redirecionar para Página Inicial */

				$('#modalClose #btnSair').click(function() {  			  

					$.ajax({
						url: 'scripts/limpar-sessao.php',										
						success: function(result) {							
							$(window.document.location).attr('href','index.php'); 								
						}

					});					

				});

				/* Lista da Tabela de Repertório */
				
				$("#lista-repertorio").load("scripts/list-repertorio.php", function() {		

					if ("<?php echo $_SESSION['perfil_usuario']; ?>" == 'Administrador') {
							$('#btnNovaMusica').css('display', 'inline-block');						
					}					

					$("a[id^='lnkMusica']").click(function() {

						/* Captura conteúdo da propriedade value da tag html 'a' */

						var id = $(this).attr('value');
					
						$("#modalExcluir #textoAlertaExcluir").html("Deseja excluir esta música?");
						$('#modalExcluir').modal('show');  

						$('#modalExcluir #btnSim').click(function() {  						

							$('#modalExcluir').modal('hide');  

							$.ajax({
								url: 
								    'scripts/delete-musica.php?id=' + id,
									success: function(resposta) {
										var resultado = resposta; 												        			        				                   
										if (resultado == 1) {											
											$(window.document.location).attr('href','musica.php');	
										} else {
											$('#modalAlerta #textoAlerta').html("Erro ao tentar excluir música!");
											$('#modalAlerta').modal('show');
										}
									}

								});	  						
								    				
	    				});
					});  									

				}); 

				/* Lista da Tabela de Usuários*/
				
				$("#lista-usuario").load("scripts/list-usuario.php", function() {		

					if ("<?php echo $_SESSION['perfil_usuario']; ?>" == 'Administrador') {
							$('#btnNovoUsuario').css('display', 'inline-block');						
					}	
					
					$("a[id^='lnkUsuario']").click(function() {

						/* Captura conteúdo da propriedade value da tag html 'a' */

						var id = $(this).attr('value');
					
						$("#modalExcluir #textoAlertaExcluir").html("Deseja excluir este usuário?");
						$('#modalExcluir').modal('show');  

						$('#modalExcluir #btnSim').click(function() {  						

							$('#modalExcluir').modal('hide');  

							$.ajax({
								url: 
								    'scripts/delete-usuario.php?id=' + id,
									success: function(resposta) {
										var resultado = resposta; 												        			        				                   
										if (resultado == 1) {											
											$(window.document.location).attr('href','usuario.php');	
										} else {
											$('#modalAlerta #textoAlerta').html("Erro ao tentar excluir usuário");
											$('#modalAlerta').modal('show');
										}
									}

								});	  						
								    				
	    				});
					});  									

				}); 

				$("#busca").keyup(function(){					
					var tabela = $(this).attr('alt');
					if( $(this).val() != ""){
						$("."+tabela+" tbody>tr").hide();
						$("."+tabela+" td:contains-ci('" + $(this).val() + "')").parent("tr").show();
					} else{
						$("."+tabela+" tbody>tr").show();
					}
				});							


			});

			$.extend($.expr[":"], {
				"contains-ci": function(elem, i, match, array) {
					return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
				}
			});	

		 </script>

	</head>

	<body>

		<div class="container">	     

			<?php														

			    if (!isset($_SESSION['nome_usuario'])) {
					echo "<script>										
						$(window.document.location).attr('href','index.php');										 	
					</script>";
				}
			?>

			<div class="page-header well">						
					<div class="control-group">
						
						<?php
						                            
							echo "<p class='msg-boas-vindas'> Seja bem vindo, " . "<strong>" . $_SESSION['nome_usuario'] . "</strong>" . "</p>";  						
							
						?>  											
						<span class="glyphicon glyphicon-off"></span>					
						<a id='lnkSair' href='#'>Sair do sistema</a>
					</div>					
										
			</div>	

			<div class="navbar navbar-default" role="navigation">
		        <div class="container-fluid">
			        <div class="navbar-header">
			            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
			              <span class="sr-only">Toggle navigation</span>
			              <span class="icon-bar"></span>
			              <span class="icon-bar"></span>
			              <span class="icon-bar"></span>
			            </button>		            
			        </div>
			        <div class="navbar-collapse collapse">
			            <ul class="nav navbar-nav">			          
				            <li><a href="default.php">Página Inicial</a></li>
				            <li><a href="musica.php" id="pesquisa">Música</a></li>				            
				            <li ID="menuUsuario" style="display:none;"><a href="usuario.php" id="usuario">Usuário</a></li>	
				            <!--<li class="dropdown">
				                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Repertório<b class="caret"></b></a>
				                <ul class="dropdown-menu">
				                    <li><a href="incluir.php">Incluir</a></li>				                   		                  
				                </ul>
				            </li> -->
			            </ul>           
			        </div><!--/.nav-collapse -->
		        </div><!--/.container-fluid -->
	      	</div>        		

	        <?php
	      		echo $pagemaincontent;
	      	?>  	      	

	    </div>   
	   
	    <div id="footer">
	    	<div class="container">    		
	    		<p class="text-muted">
	    			Copyright © 2006-2014 - <a href="http://ibmontesiao.com">Igreja Batista Monte Sião</a> - Todos direitos Reservados.
	    		</p>
	    	</div>
		</div>    

		<!-- MODALS --> 
		
		<div id="modalClose" class="modal fade">
			  <div class="modal-dialog modal-sm">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			        <h3 class="modal-title text-center">Alerta</h3>
			      </div>
			      <div class="modal-body">
			        <h5 id="textoAlertaClose"></h5>
			      </div>
			      <div class="modal-footer">			       
			        <button type="button" id="btnSair" class="btn btn-primary">Sim</button>
			        <button type="button" class="btn btn-default" data-dismiss="modal">Não</button>
			      </div>
			    </div><!-- /.modal-content -->
			  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->

		<div id="modalExcluir" class="modal fade">
			  <div class="modal-dialog modal-sm">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			        <h3 class="modal-title text-center">Alerta</h3>
			      </div>
			      <div class="modal-body">
			        <h5 id="textoAlertaExcluir"></h5>
			      </div>
			      <div class="modal-footer">			       
			        <button type="button" id="btnSim" class="btn btn-primary">Sim</button>
			        <button type="button" class="btn btn-default" data-dismiss="modal">Não</button>
			      </div>
			    </div><!-- /.modal-content -->
			  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->

		<div id="modalAlerta" class="modal fade">
			<div class="modal-dialog modal-sm">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			        <h3 class="modal-title text-center">Alerta</h3>
			      </div>
			      <div class="modal-body">
			        <h5 id="textoAlerta"></h5>
			      </div>
			      <div class="modal-footer">			       
			        <button type="button" id="btnOk" class="btn btn-primary" data-dismiss="modal">OK</button>		        
			      </div>
			    </div><!-- /.modal-content -->
			</div><!-- /.modal-dialog -->
		</div><!-- /.modal -->

		<div id="modalAlertaCadastroMusica" class="modal fade">
			<div class="modal-dialog modal-sm">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			        <h3 class="modal-title text-center">Alerta</h3>
			      </div>
			      <div class="modal-body">
			        <h5 id="textoAlertaMusica"></h5>
			      </div>
			      <div class="modal-footer">			       
			        <button type="button" id="btnOkCadastroMusica" class="btn btn-primary">OK</button>		        
			      </div>
			    </div><!-- /.modal-content -->
			</div><!-- /.modal-dialog -->
		</div><!-- /.modal -->

		<div id="modalAlertaEditaMusica" class="modal fade">
			<div class="modal-dialog modal-sm">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			        <h3 class="modal-title text-center">Alerta</h3>
			      </div>
			      <div class="modal-body">
			        <h5 id="textoAlertaMusica"></h5>
			      </div>
			      <div class="modal-footer">			       
			        <button type="button" id="btnOkEditaMusica" class="btn btn-primary">OK</button>		        
			      </div>
			    </div><!-- /.modal-content -->
			</div><!-- /.modal-dialog -->
		</div><!-- /.modal -->

		<div id="modalAlertaCadastroUsuario" class="modal fade">
			<div class="modal-dialog modal-sm">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			        <h3 class="modal-title text-center">Alerta</h3>
			      </div>
			      <div class="modal-body">
			        <h5 id="textoAlertaUsuario"></h5>
			      </div>
			      <div class="modal-footer">			       
			        <button type="button" id="btnOkCadastroUsuario" class="btn btn-primary">OK</button>		        
			      </div>
			    </div><!-- /.modal-content -->
			</div><!-- /.modal-dialog -->
		</div><!-- /.modal -->

		<div id="modalAlertaEditaUsuario" class="modal fade">
			<div class="modal-dialog modal-sm">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			        <h3 class="modal-title text-center">Alerta</h3>
			      </div>
			      <div class="modal-body">
			        <h5 id="textoAlertaUsuario"></h5>
			      </div>
			      <div class="modal-footer">			       
			        <button type="button" id="btnOkEditaUsuario" class="btn btn-primary">OK</button>		        
			      </div>
			    </div><!-- /.modal-content -->
			</div><!-- /.modal-dialog -->
		</div><!-- /.modal -->	

		<script>

			$(document).ready(function() {    	
				$('#menuUsuario').css('display', 'inline-block');
			});

		</script>
	   
	</body>

</html>
